package cn.itsource.pethome.basic.controller;

import cn.itsource.pethome.basic.service.IVerificationCodeService;
import cn.itsource.pethome.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verification")
public class VerificationCodeController {

    @Autowired
    private IVerificationCodeService verificationCodeService;

    @PostMapping("/sendRegisterMobileCode")
    public AjaxResult sendRegisterMobileCode(@RequestBody Map<String,String> param){
        try {
            //获取手机号
            String phone = param.get("phone");
            //根据手机号发送验证码
            verificationCodeService.sendRegisterMobileCode(phone);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,e.getMessage());
        }

    }
    //发送绑定的验证码
    @PostMapping("/sendBinderMobileCode")
    public AjaxResult sendBinderMobileCode(@RequestBody Map<String,String> param){
        try {
            //获取手机号
            String phone = param.get("phone");
            //根据手机号发送验证码
            verificationCodeService.sendBinderMobileCode(phone);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,e.getMessage());
        }

    }
}
